﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

/*
 * Author:Conis
 * Date:
 * Description:SQL语句的条件块
 */

namespace Conis.Squirrel.SqlBuilder.Oracle
{
    /// <summary>
    /// SQL语句的条件块
    /// </summary>
    public class ConditionBlock : BaseConditionBlock
    {
        protected internal ConditionBlock(Connector connector) : base(connector) { }

        /// <summary>
        /// 创建参数
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        protected override IDataParameter CreateParameter(string key, object value)
        {
            return new OracleParameter(key, value);
        }

        /// <summary>
        /// 添加比较单元
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connector"></param>
        /// <param name="fieldName"></param>
        /// <param name="compare"></param>
        /// <param name="value"></param>
        /// <param name="valueIsSafe"></param>
        protected override void AddCompareUnit<T>(Connector connector, string fieldName, CompareOperator compare, T value, bool valueIsSafe)
        {
            BaseCompareUnit<T> unit = new CompareUnit<T>(connector, fieldName, compare, value, valueIsSafe);
            this.Add(unit);
        }

        /// <summary>
        /// 添加Between单元
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connector"></param>
        /// <param name="fieldName"></param>
        /// <param name="startValue"></param>
        /// <param name="endValue"></param>
        protected override void AddBetweenUnit<T>(Connector connector, string fieldName, T startValue, T endValue)
        {
            BaseBetweenUnit<T> unit = new BetweenUnit<T>(connector, fieldName, startValue, endValue);
            this.Add(unit);
        }

        /// <summary>
        /// 添加语句块
        /// </summary>
        /// <param name="connector"></param>
        /// <returns></returns>
        public override BaseConditionBlock AddBlock(Connector connector)
        {
            BaseConditionBlock block = new ConditionBlock(connector);
            this.Add(block);
            return block;
        }
    }
}
